package com.ego.common.constant;

import org.apache.commons.lang3.StringUtils;

/**
 * @program: ego
 * @description: 会员（用户）常量及枚举
 * @author: KamTang
 * @create: 2022-12-13 11:29
 **/
public class MemberConstant {
    /**
     * 验证码缓存前缀
     */
    public static final String CODE_CACHE_PREFIX = "sms:code:";

    /**
     * 已经登录的会员（用户）
     */
    public static final String LOGGED_USER = "loggedUser";

    /**
     * 临时用户的cookie key
     */
    public static final String TEMP_USER_COOKIE_NAME = "user-key";

    /**
     * 临时用户的存活时间
     */
    public static final int TEMP_USER_COOKIE_LIFETIME = 60 * 60 * 24 * 30;

    /**
     * 默认会员等级id
     */
    public static final Long DEFAULT_MEMBER_LEVEL = 1L;

    /**
     * 默认会员收货地址状态
     */
    public static final Long DEFAULT_RECEIVE_ADDRESS = 1L;

    /**
     * 微博
     */
    public static final String WEIBO_PLATFORM = "weibo";

    /**
     * 支付宝
     */
    public static final String ZFB_PLATFORM = "zfb";

    /**
     * QQ
     */
    public static final String QQ_PLATFORM = "qq";

    public enum LoginMode {
        /**
         * 微博、支付宝、QQ
         */
        WEIBO("weibo"),
        ZFB("zfb"),
        QQ("qq");

        private final String value;

        LoginMode(String value) {
            this.value = value;
        }

        /**
         * 根据 value 获取枚举
         */
        public static LoginMode getEnumByValue(String value) {
            if (StringUtils.isBlank(value)) {
                return null;
            }
            for (LoginMode loginMode : LoginMode.values()) {
                if (loginMode.value.equals(value)) {
                    return loginMode;
                }
            }
            return null;
        }

        public String getMode() {
            return value;
        }
    }
}
